package com.vecspace.testhelper.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.vecspace.database.dao.BaseDao;

@Repository("test_testHelperDao")
public class TestHelperDao extends BaseDao{
	/**
	 * 查询一条记录
	 * @param sql
	 * @param params
	 * @return
	 * @throws Exception 
	 * @author: wanghua
	 */
	public Map<String, Object> queryRow(String sql, Object[] params) throws Exception{
		Map<String, Object> row = this.queryDataRowMap(sql, params);
		return row;
	}
	
	/**查询多条记录
	 * 
	 * @param sql
	 * @param params
	 * @return
	 * @throws Exception 
	 * @author: wanghua
	 */
	public List<Map<String, Object>> queryRows(String sql, Object[] params) throws Exception{
		List<Map<String, Object>> rows;
		if(params == null || params.length == 0) {
			rows = this.queryDataRowMapList(sql);
		}else {
			rows = this.queryDataRowMapList(sql, params);
		}		
		return rows;
	}
	
	/**执行insert，update或者delete语句
	 * 
	 * @param sql
	 * @param params
	 * @return
	 * @throws Exception 
	 * @author: wanghua
	 */
	public int executeSql(String sql , Object[] params) throws Exception {
		int rcount = this.updateDataRowBySql(sql, params);
		return rcount;
	}
	
	public String getString(String sql, Object[] params) throws Exception {
		String val;
		if(params == null || params.length == 0) val = super.queryString(sql);
		else val = super.queryString(sql, params);
		return val;
	}
	

	public int getInt(String sql, Object[] params) throws Exception {
		int val;
		if(params == null || params.length == 0) val = super.queryInt(sql);
		else val = super.queryInt(sql, params);
		return val;
	}
	

	public Date getDate(String sql, Object[] params) throws Exception {
		Object val;
		if(params == null || params.length == 0) val = super.queryValue(sql);
		else val = super.queryValue(sql, params);
		if(val != null && val instanceof Date) {
			return (Date)val;
		}else return null;
	}
	

	public long getLong(String sql, Object[] params) throws Exception {
		long val;
		if(params == null || params.length == 0) val = super.queryLong(sql);
		else val = super.queryLong(sql, params);
		return val;
	}	
}
